package org.easymodelers.gmf.creator.impl;

import java.io.IOException;
import java.util.List;

import org.easymodelers.gmf.creator.GmfCreatorException;
import org.easymodelers.gmf.creator.GmfMapCreator;
import org.easymodelers.gmf.utils.ModelsManager;
import org.easymodelers.modeler.data.ModelerDefinition;
import org.easymodelers.processing.ModelerUpdate;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.gmf.gmfgraph.Canvas;
import org.eclipse.gmf.mappings.GMFMapFactory;
import org.eclipse.gmf.mappings.Mapping;
import org.eclipse.gmf.tooldef.ToolRegistry;

public class GenericGmfMapCreator extends AbstractGenericGmfCreator<Mapping> implements GmfMapCreator {

	protected ModelsManager createModelsManager(String modelPath) {
		try {
			Canvas canvas = getGmfGraphModelFromGmfMapModel(modelPath);
			ToolRegistry toolRegistry = getGmfToolModelFromGmfMapModel(modelPath);
			EPackage metaModel = getMetaModelFromGmfMapModel(modelPath);

			Mapping mapping = GMFMapFactory.eINSTANCE.createMapping();
			return new ModelsManager(canvas, toolRegistry, mapping, metaModel);
		} catch(IOException ex) {
			String message = "Error during initializing models manager.";
			throw new GmfCreatorException(message, ex);
		}
	}

	protected Mapping getRootEObject(ModelsManager modelsManager) {
		return modelsManager.getMapping();
	}

	public void registerDefaultElementDefinitionHandlers() {
	}

	public List<ModelerUpdate> createGmfMap(String modelPath, ModelerDefinition modeler) throws IOException {
		return createGmfModel(modelPath, modeler);
	}
}
